<template>

  <!--图片上传方法-->
  <!--<el-upload
    :http-request="uploadImg"
    :headers="myHeaders"
    list-type="picture-card"
    :on-success="duil"
    :on-error="cuol"
    :on-preview="handlePictureCardPreview"
    :on-remove="handleRemove">
    <i class="el-icon-plus"></i>
  </el-upload>
  <el-dialog :visible.sync="dialogVisible">
    <img width="100%" :src="dialogImageUrl" alt="">
  </el-dialog>-->


  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">商品</el-breadcrumb-item>
      <el-breadcrumb-item>商品评论</el-breadcrumb-item>
    </el-breadcrumb>
    <div>
      <el-image :src="information.url" style="width: 400px;display:inline-block;margin: 20px"/>
      <div style="display:inline-block;vertical-align:top;padding-top: 20px">
        <p><el-tag type="success">商品名称</el-tag>{{information.goodsName}}</p>
        <p><el-tag type="success">评价人数</el-tag>{{information.buyCount}}</p>
        <p><el-tag type="success">综合评分</el-tag>
          <el-rate
            v-model="information.point"
            :colors="colors" disabled style="display: inline-block">
          </el-rate>
        </p>
      </div>
    </div>

    <!--批量删除按钮-->
    <el-button size="small" type="warning" icon="el-icon-delete-solid" @click="goodsDelete(multipleSelection)" style="margin-bottom: 10px">全部删除</el-button>
    <!--列表-->

    <!--    {-->
    <!--    managerAccountNumber:'manager001',-->
    <!--    managerName:'池松松',-->
    <!--    roleName:'超级管理员',-->
    <!--    managerGender:'1',-->
    <!--    insertTime:'2022-5-20 15:21',-->
    <!--    modifiedTime:'2022-5-20 15:21',-->
    <!--    }-->

    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中"   @selection-change="handleSelectionChange" style="width: 100%;">
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
      <el-table-column type="index" sortable  label="序号" width="200" :index='indexMethod'>
      </el-table-column>
      <el-table-column sortable prop="userUserId" label="用户id" width="150">
      </el-table-column>
      <el-table-column sortable prop="userName" label="用户名称" width="150">
      </el-table-column>
      <el-table-column sortable prop="insertTime" label="评论时间" width="100" >
      </el-table-column>
      <el-table-column sortable prop="comment" label="评价内容" width="220">
      </el-table-column>
      <el-table-column sortable prop="buyCount" label="购买数量" width="220">
      </el-table-column>
      <el-table-column sortable prop="mark" label="评分" width="220" >
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button size="mini" @click="goToPage(scope.row)">详情</el-button>
          <el-button size="mini" type="danger" @click="goodsDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:childMsg="pageparm" @callFather="callFather"></Pagination>
  </div>
</template>

<script>
  import {goodsCommentByGoodsId} from "../../api/mallMG.js";
  import Pagination from '../../components/Pagination'
  export default {
    name: "Brand",
    data(){
      return {
        information:{
          buyCount:'',
          point:'',
          goodsName:'',
          url:''
        },
        point:4.7,
        value1:true,
        nshow: true, //switch开启
        fshow: false, //switch关闭
        loading: false, //是显示加载
        editFormVisible: false, //控制编辑页面显示与隐藏
        title: '添加',
        colors: ['#99A9BF', '#F7BA2A', '#FF9900'],  // 等同于 { 2: '#99A9BF', 4: { value: '#F7BA2A', excluded: true }, 5: '#FF9900' }
        editForm: {
          managerAccountNumber: '',
          managerName: '',
          roleNumber: '',
          managerGender: '',
          token: localStorage.getItem('logintoken')
        },
        // rules表单验证
        rules: {
          managerAccountNumber: [{ required: true, message: '请输入管理员名称', trigger: 'blur' }],
          managerName: [{ required: true, message: '请输入管理员名称', trigger: 'blur' }],
          roleNumber:[{required: true, message: '请选择',trigger: 'blur'}],
          managerGender:[{required: true, message: '请选择',trigger: 'blur'}]
        },
        formInline: {
          page: 1,
          limit: 10,
          goodsId: this.$route.params.goodsId,
          token: localStorage.getItem('logintoken')
        },
        userparm: [], //搜索权限
        listData: [
          {
            number:'123',
            name:'百事可乐',
            brandName:'可口可乐',
            commentCount:'16',
            price:'20',
            //1-普通，2-门店自提，3-国外直邮
            logistics:1,
            //状态(0-未上架 1-已上架)
            state:1,
          }
        ], //用户数据
        currentRow:null,
        multipleSelection:[],
        roles:[
          {
            roleNumber:'001',
            roleName:"超级管理员"
          }
        ],
        // 分页参数
        pageparm: {
          currentPage: 0,
          pageSize: 10,
          total: 0
        },


        dialogImageUrl: '',
        dialogVisible: false,
        myHeaders:{'Access-Control-Allow-Origin':'*'}
      };
    },
    created() {
      this.goodsCommentByGoodsId(this.formInline)
    },
    components: {
      Pagination
    },
    methods: {
      // openClick(){
      //
      //   //alert("666")
      //   this.value1=!this.value1
      //   //this.value1=false
      //   alert(this.value1)
      // },
      goToPage(row){
        this.$router.push('/mall/GoodsDetail/'+row.id)
      },

      formatRole1:function(row,column){
        if(row.logistics==1){
          return "普通快递"
        }
        else if(row.logistics==2){
          return "国外直邮"
        }
        else if(row.logistics==3){
          return "门店自提"
        }
        return ""
      },

      /*列表*/
      goodsCommentByGoodsId(data){
        this.loading = true
        goodsCommentByGoodsId(data).then(res=>{
          /*
          * R.ok().data("data",page1).
                data("buyCount",buyCount).
                data("point",point).
                data("goodsName",goodsName).
                data("url",url);
          * */
          //console.log(JSON.stringify(res.data.data))
          let tagObject=res.data.data
          //alert(JSON.stringify(tagObject))
          this.listData = tagObject.records
          this.pageparm.currentPage = tagObject.current;
          this.pageparm.pageSize = tagObject.size
          this.pageparm.total = tagObject.total;
          this.formInline.page = tagObject.current;
          this.formInline.limit = tagObject.size

          this.information.point=res.data.point
          this.information.goodsName=res.data.goodsName
          this.information.buyCount=res.data.buyCount
          this.information.url=res.data.url
          this.loading = false
        }).catch(error=>{
          alert(JSON.stringify(error))
        })
      },
      // 批量删除
      goodsDelete(row){
        let rows=[];
        if(Array.isArray( row)){
          rows=row
        }else{
          rows.push(row)
        }
        this.$confirm('确定要删除吗?', '信息', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(()=>{
          let managerAccountNumbers=[]
          rows.forEach(goods=>{
            //alert(JSON.stringify(goods))
            managerAccountNumbers.push(goods.id)
          })
          let param={ids:managerAccountNumbers}
          this.loading=true
          alert(JSON.stringify(param))
          goodsDeletes(param).then(res=>{
            if(res.success){
              this.loading=false
              this.$message({
                type: 'success',
                message: '删除成功'
              })
              goodsList()
            }else{
              let managerAccountNumbers=res.data
              this.loading=false
              this.$message({
                type: 'error',
                message: '删除失败，未删除的:'+JSON.stringify(managerAccountNumbers)
              })
            }
            this.getData(this.formInline)
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
      // 多选框
      handleSelectionChange(val){
        this.multipleSelection=val;
      },
      // 分页插件事件
      callFather(parm) {
        this.formInline.page = parm.currentPage
        this.formInline.limit = parm.pageSize
        this.goodsCommentByGoodsId(this.formInline)
      },
      // 显示序列号
      indexMethod(index){

        let curpage = this.pageparm.currentPage; //单前页码，具体看组件取值
        let limitpage = this.pageparm.pageSize; //每页条数，具体是组件取值
        return index + 1 + (curpage - 1) * limitpage;
      },
    }
  }
</script>

<style>

  .avatar-uploader {
    text-align: center;
    padding-bottom: 10px;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 138px;
    height: 138px;
    line-height: 138px;
    text-align: center;
  }
  .avatar {
    width: 138px;
    height: 138px;
    display: block;
  }
</style>
